package com.shiwaixiangcun.customer.base;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.Toast;

import com.baidu.mobstat.SendStrategyEnum;
import com.baidu.mobstat.StatService;
import com.shiwaixiangcun.customer.R;
import com.shiwaixiangcun.customer.ui.fragment.CubeFragmentActivity;
import com.shiwaixiangcun.customer.utils.StatusBarUtils;

/**
 * Activity 基类
 *
 * @author Administrator
 */

@SuppressLint("Registered")
public class BaseActivity extends CubeFragmentActivity {
    /**
     * 日志输出标志
     **/
    protected final String BUG_TAG = this.getClass().getSimpleName();
    protected Context mContext = null;
//    protected ImmersionBar mImmersionBar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        StatusBarUtils.setLightMode(this);
        StatusBarUtils.setColor(this, getResources().getColor(R.color.ui_white), 0);
        mContext = this;
        StatService.setLogSenderDelayed(10);
        StatService.setSendLogStrategy(this, SendStrategyEnum.APP_START, 1, false);
        StatService.setSessionTimeOut(30);
//        //初始化沉浸式
//        if (isImmersionBarEnabled()) {
//            initImmersionBar();
//        }

    }

//    protected void initImmersionBar() {
//        //在BaseActivity里初始化
//        mImmersionBar = ImmersionBar.with(this);
//        mImmersionBar.fitsSystemWindows(true)
//                .statusBarColor(R.color.colorPrimary)
//                .init();
//    }

    @Override
    protected void onResume() {
        super.onResume();
        StatService.onResume(this);
    }

    /**
     * 是否可以使用沉浸式
     * Is immersion bar enabled boolean.
     *
     * @return the boolean
     */
    protected boolean isImmersionBarEnabled() {
        return true;
    }

    @Override
    protected void onPause() {
        super.onPause();
        StatService.onPause(this);
    }

    protected void readyGo(Class<?> clazz) {
        Intent intent = new Intent(this, clazz);
        startActivity(intent);
    }


    protected void readyGo(Class<?> clazz, Bundle bundle) {
        Intent intent = new Intent(this, clazz);
        if (null != bundle) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }

    protected void readyGoThenKill(Class<?> clazz) {
        Intent intent = new Intent(this, clazz);
        startActivity(intent);
        finish();
    }

    protected void readyGoThenKill(Class<?> clazz, Bundle bundle) {
        Intent intent = new Intent(this, clazz);
        if (null != bundle) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
        finish();
    }

    protected void readyGoForResult(Class<?> clazz, int requestCode) {
        Intent intent = new Intent(this, clazz);
        startActivityForResult(intent, requestCode);
    }

    protected void readyGoForResult(Class<?> clazz, int requestCode, Bundle bundle) {
        Intent intent = new Intent(this, clazz);
        if (null != bundle) {
            intent.putExtras(bundle);
        }
        startActivityForResult(intent, requestCode);
    }


    protected void showToastShort(CharSequence charSequence) {

        Toast.makeText(mContext, charSequence, Toast.LENGTH_SHORT).show();
    }

    protected void showToastLong(CharSequence charSequence) {

        Toast.makeText(mContext, charSequence, Toast.LENGTH_LONG).show();
    }

    @Override
    protected String getCloseWarning() {
        return null;
    }

    @Override
    protected int getFragmentContainerId() {
        return 0;
    }

    @Override
    protected void onDestroy() {

//        //必须调用该方法，防止内存泄漏，不调用该方法，如果界面bar发生改变，在不关闭app的情况下，退出此界面再进入将记忆最后一次bar改变的状态
//        if (mImmersionBar != null) {
//            mImmersionBar.destroy();
//        }
        super.onDestroy();


    }
}
